using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;

namespace YayiMgr.Ability.Docking.Commom
{
    public class QueryListDto<T>
    {
        public int Code { get; set; }
        public string? Message { get; set; }
        public List<T>? Data { get; set; }
        public int Total { get; set; }
        public int PageCount { get; set; }
        public int PageIndex { get; set; }
        public int PageSize { get; set; }

        public static QueryListDto<T> Create(List<T> data, int total, int pindex, int psize, int code = 200, string message = "成功")
        {
            return new QueryListDto<T>{
                Data = data,
                Message = message,
                Total = total,
                PageCount = psize == 0 ? 1 : (total / psize + ((total % psize) == 0 ? 0 : 1)),
                PageIndex = pindex,
                PageSize = psize,
                Code = code
            };
        }

        // public static async QueryListDto<T1> CreateQueryListDto<T0, T1>(IQueryable<T0> DataQry, QueryByPage page)
        // {            
        //     int total = DataQry.Count();//.CountAsync();
        //     List<T0> list = await DataQry.OrderBy(p=>p.Account).Skip((page.PageIndex-1)*page.PageSize).Take(page.PageSize).ToListAsync();
        //     List<T1> Data =  ModelMapper.Map<List<T0>,List<T1>>(list);
        //     QueryListDto<T> listDto = QueryListDto<T>.Create(Data, "成功", total, page.PageIndex, page.PageSize);

        //     // return new QueryListDto<T>{
        //     //     Data = data,
        //     //     Message = message,
        //     //     Total = total,
        //     //     PageCount = total / psize + ((total % psize) == 0 ? 0 : 1),
        //     //     PageIndex = pindex,
        //     //     PageSize = psize,
        //     //     Code = code
        //     // };
        // }
    }
}